# 基于官方的alpine镜像构建镜像
FROM ubuntu:latest

# 安装必要的软件
RUN apt-get update && apt-get install -y openssh-server python3 rsync

# 将frpc文件拷贝到容器中的 /app 目录下
COPY . /app

WORKDIR /app

# 创建用户
RUN useradd -m -d /home/dockeruser -s /bin/bash dockeruser

# 安装 SSH 服务器的配置文件和密钥
RUN echo 'dockeruser:qwe147258' | chpasswd

RUN usermod -aG sudo dockeruser

# 启用SSH服务
RUN service ssh start
# 更改SSH服务器配置以允许密钥身份验证
RUN echo "PasswordAuthentication no" >> /etc/ssh/sshd_config && \
    echo "AuthorizedKeysFile     /home/dockeruser/.ssh/authorized_keys" >> /etc/ssh/sshd_config && \
    echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config
#    echo "RSAAuthentication yes" >> /etc/ssh/sshd_config && \

# RUN pip install -r requirements.txt

RUN chmod +x /app/frpc
RUN chmod +x /app/start.sh
RUN mkdir /data
RUN chmod -R 777 /data/
USER dockeruser

#生成密钥
RUN ssh-keygen -t rsa -b 4096 -C "dockeruser@dell.com" -N "" -f ~/.ssh/id_rsa

# 创建authorized_keys文件并复制公钥内容
#其中authorized_keys应该包含了deckmanager和ankisync两个服务器的密钥
RUN mkdir -p /home/dockeruser/.ssh && \
    touch /home/dockeruser/.ssh/authorized_keys && \
    cat ./authorized_keys >> /home/dockeruser/.ssh/authorized_keys

# RUN ssh-copy-id ubuntu@159.75.180.229

USER root

RUN mkdir -p /data/syncserver_bk

#CMD ["/usr/sbin/sshd" "-D"]
#CMD ["/app/frpc"]
CMD ["/bin/sh", "/app/start.sh"]


